package com.ocl.www.service;

import java.util.List;

import com.ocl.www.domain.Comment;
import com.ocl.www.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ocl.www.config.TargetDataSource;
import com.ocl.www.domain.Article;
import com.ocl.www.mapper.ArticleMapper;

@Service
public class ArticleService {

	@Autowired
	private ArticleMapper articleMapper;

	/**
	 * 查询所有文章记录，按照点赞数排序
	 * @return
	 * @throws Exception
	 */
	public List<Article> selectAllArticleOrderByLikeCount()throws  Exception{

		return articleMapper.selectAllArticleOrderByLikeCount();

	}

	public List<Article> selectAllArticle()throws  Exception{
		
		List<Article> list = null;

		list = articleMapper.selectAllArticle();

		
		return list;
		
	}

	public int insertArticle(Article art) throws  Exception{
		// TODO Auto-generated method stub
		int c =  0;

			c =  articleMapper.insertArticle(art);

		return c;
	}
	public List<Article>  selectArticles(Article art) throws  Exception{
		// TODO Auto-generated method stub
		List<Article> list = null;

			list = articleMapper.selectArticles(art);

		
		return list;
	}

	public Article  selectArticle(Article art) throws  Exception{
		// TODO Auto-generated method stub

			art = articleMapper.selectArticle(art);


		return art;
	}

    public List<Article> queryArticles() throws  Exception{
		List<Article> list = null;

			list = articleMapper.queryArticles();

		return list;
    }


    public int addOneLikeCount(Article art) throws  Exception{
		int c = articleMapper.addOneLikeCount(art);
		return c ;
	}

	public int ReduceOneLikeCount(Article art) throws  Exception{
		int c = articleMapper.ReduceOneLikeCount(art);
		return c;
	}

    public List<Article> selectArticlesOfUser(User user) throws Exception{
		return articleMapper.selectArticlesOfUser(user);
    }

    public List<Article> selectArticleList(List<Integer> articleids)throws  Exception{

		return articleMapper.selectArticleList( articleids);
	}

    public int addOneCommCount(Comment comm)  throws  Exception{

		return articleMapper.addOneCommCount(comm);

    }
}
